/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;

import entidades.Alumno;
import java.util.List;
import javax.ejb.Stateless;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Administrador
 */
@Stateless
public class AlumnoFacade extends AbstractFacade<Alumno> {
    @PersistenceContext(unitName = "SistemasDistribuidos-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public AlumnoFacade() {
        super(Alumno.class);
    }
    
    public boolean getAlumnobyLegajo(Alumno alumno, Long legajo){
        
        boolean retorno = false;
        try{
            Query query = em.createQuery("SELECT a FROM Alumno a WHERE a.legajo = :legajo ");
            query.setParameter("legajo", legajo);
            alumno.sobreescribir((Alumno) query.getSingleResult());
            retorno = true;
        } catch (NoResultException nre) {
            alumno = new Alumno();
            nre.printStackTrace();
        } finally {
            return retorno;
        }
        
    }
    
}
